﻿/// <reference path="_references.js" />
var pageJs = {
    requestId: '',
    wpAjaxFun: function (url, paramters, successFun, errFun, loadHiddenFun) {
        if (paramters) paramters.requestId = this.requestId;//增加请求时序标识
        else {
            paramters = { "requestId": this.requestId };
        };
        $.ajax({
            url: url,
            data: JSON.stringify(paramters),
            type: 'post',
            cache: false,
            contentType: "application/json; charset=utf-8",
            dataType: 'json',
            success: function (data) {
                successFun(data.d)
                if (typeof (loadHiddenFun) == "function")//判断是否需要关闭加载状态
                    loadHiddenFun();
            },
            error: errFun ? errFun : function (XMLHttpRequest, textStatus, errorThrown) {
                if (typeof (loadHiddenFun) == "function")
                    loadHiddenFun();
                //alert(XMLHttpRequest.status);
                //alert(XMLHttpRequest.readyState);
                alert(textStatus);
            },
            complete: function (XMLHttpRequest, textStatus) {

            }
        });
    },
    loadAjaxFun: function (url, paramters, successFun, errFun) {
        if (typeof (loadSign) == "undefined") {
            loadSign = ".loading";
        }
        $(loadSign).show();
        this.wpAjaxFun(url, paramters, successFun, errFun, function () {
            $(loadSign).hide();
        });
    },
    showDialog: function (contentId, closeFun) {
        $.fancybox.open({
            href: "#" + contentId
        }, {
            closeBtn: false,
            closeClick: false,
            beforeClose: closeFun,
            helpers: {
                overlay: {
                    closeClick: false
                }
            }
        })
    },
    closeDialog: function (closeFun) {
        if (typeof (closeFun) == "fucntion")
            closeFun();
        $.fancybox.close();
    },
    initDropdownList: function (sourceUrl, paramters, wrapId) {
        this.wpAjaxFun(sourceUrl, paramters, function (data) {
            if (data.ActionResult) {
                $("#" + wrapId).html("");
                for (var i = 0; i < data.Data.length; i++) {
                    $("#" + wrapId).append('<option value="' + data.Data[i].SelectVal + '" title="' + data.Data[i].Remark + '"">' + data.Data[i].SelectName + '</option>');
                };
            } else { }
        });
    }
}